<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('功能配置列表')" />
	<style type="text/css">
		label.layui-form-label {width: 95px;padding-right: 0px;}
	</style>
</head>
<body>
<form>
	<div class="layuiadmin-header-box">
		<th:block th:include="listinclude :: searchTop" />
	</div>
</form>
<div class="mid-content">
    <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
</div>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" onclick="$.operate.add()" shiro:hasPermission="system:dictionaryformodule:add">
            <p class="dhicon dh-plus" style="color:white;font-size:14px"><span class="fa_span">新增</span></p>
        </div>
    </div>
</script>
<script type="text/html" id="barDh">
	<a class="layui-btn layui-btn-xs dhicon dh-edit" onclick="$.operate.edit('{{d.guid}}')"  shiro:hasPermission="system:dictionaryformodule:edit">&nbsp;编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" onclick="remove('{{d.guid}}')" shiro:hasPermission="system:dictionaryformodule:delete">&nbsp;删除</a>
	<a class="layui-btn layui-btn-warm layui-btn-xs dhicon dh-television" onclick="newTab('{{d.moduleTable}}','{{d.moduleName}}','{{d.moduleAlias}}')" shiro:hasPermission="system:dictionaryforfield:list">&nbsp;PC</a>
	<a class="layui-btn layui-btn-warm layui-btn-xs layui-icon layui-icon-cellphone" onclick="newTab('{{d.moduleTable}}','{{d.moduleName}}','{{d.moduleAlias}}',true);" shiro:hasPermission="system:dictionaryformobilefield:list">&nbsp;手机</a>
	<a class="layui-btn layui-bg-cyan layui-btn-xs dhicon dh-external-link-square" onclick="newTab2('{{d.moduleTable}}','{{d.moduleName}}','{{d.moduleAlias}}')" shiro:hasPermission="system:dictionaryformodule:edit">&nbsp;关联</a>
</script>
<script type="text/html" id="checkbox_moduleState">
    <input type="checkbox" value="{{d.guid}}" lay-skin="switch" lay-text="启用|停用" name="moduleState" lay-filter="change" {{ d.moduleState=== "1" ? 'checked' : '' }}>
</script>
<script type="text/html" id="checkbox_moduleBidAddCon">
    <input type="checkbox" value="{{d.guid}}" lay-skin="switch" lay-text="启用|停用" name="moduleBidAddCon" lay-filter="change" {{ d.moduleBidAddCon? 'checked' : '' }}>
</script>
<script type="text/html" id="checkbox_moduleEnableSet">
    <input type="checkbox" value="{{d.guid}}" lay-skin="switch" lay-text="启用|停用" name="moduleEnableSet" lay-filter="change" {{ d.moduleEnableSet? 'checked' : '' }}>
</script>
<script type="text/html" id="checkbox_appEnable">
    <input type="checkbox" value="{{d.guid}}" lay-skin="switch" lay-text="启用|停用" name="appEnable" lay-filter="change" {{ d.appEnable? 'checked' : '' }}>
</script>
<script type="text/html" id="dropdown_menuGuid">
	<select name="menuGuid" id="menuGuid" th:with="type=${@baseinfosimple.getMenuFieldFrontConditions('notSet')}">
		<option value="">请选择</option>
		<option th:each="dict : ${type}" th:text="${dict.menuCaption}" th:value="${dict.guid}"></option>
	</select>	
</script>
<th:block th:include="include :: footer" />
<th:block th:include="listinclude :: list-templeat" />
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "system/dictionaryformodule";
	var nextMenuMap=[[${nextMenuMap}]];
	var gridColumns=[[${gridColumns}]];
	var moduleTable=[[${moduleTable}]];
	console.log("gridColumns",gridColumns)
	/*]]>*/
</script>
<script type="text/javascript">
var $,layer,form,table,wherestr={};
layui.use(['table','form','layer','jquery'], function () {
     $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table;
     //表单初始化
     $.tablelist.init({
         elem: '#dhtable'
	     ,modalName: "功能"
         ,url: prefix + "/list"
         ,createUrl: prefix + "/add"
         ,updateUrl: prefix + "/edit?guid={id}"
		 ,totalRow: gridColumns.totalRow
		 ,cols: [gridColumns.gridBody
		 ]
        ,toolbar: '#toolbar'
    	,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
        ,height:'full-90'
     });
	//监听排序事件 
     table.on('sort(ftable)', function(obj){
     	$.tablelist.sort('dhtable',obj);
     });
   	//头工具栏事件
  	table.on('toolbar(ftable)', function(obj){
  	    switch(obj.event){
  	    	case 'fieldSet':
  	    		filedSet(moduleTable);
           	break;
  	    };
  	});
 	//搜索按钮
 	$('#btn-search').on('click', function () {
 		$.each(wherestr,function(i,v){$("#"+i).val()?wherestr[i]=$("#"+i).val():wherestr[i]='';});//动态获取条件的值
        table.reload('dhtable', {page: {curr: 1},where:wherestr});
     });
 	//监听下拉框——添加条件
 	form.on('select(fft)', function(obj){
 		addMore(this);
 	});
	//监听开关动作
 	form.on('switch(change)', function(obj){
 		var data={};
 		data['guid']=obj.value;
 		if(obj.elem.checked==true){
 			data[obj.elem.name]=1;
  	    	$.operate.post(prefix + "/editpost", {'dictionaryForModuleItems':JSON.stringify([data])}); 
    	}else{
    		data[obj.elem.name]=0;
	    	$.operate.post(prefix + "/editpost", {'dictionaryForModuleItems':JSON.stringify([data])});
	    }
    });
});
function createFile(dbt,mdu){
	layer.open({
       	type: 1,
		title: '生成代码',
		offset: '20%',//距离顶部10%
		area: ['385px','200px'],
		btn: ['生成','取消'],
		shadeClose: true,//点击弹层外区域关闭
		content: '<div class="layui-form-pane" style="margin:8px 20px">'+
// 					'<p style="color:red;text-align:center;height:30px">提示语句</p>'+
					'<label class="layui-form-label" style="width:120px">代码名</label>'+
					'<input style="width:200px" type="text" id="tableName" class="layui-input layui-input-block"></div>'+
					'<div class="layui-form-pane" style="margin:8px 20px">'+
					'<label class="layui-form-label" style="width:120px">模块名</label>'+
					'<input style="width:200px" type="text" id="moduleName" class="layui-input layui-input-block"></div>',
		success: function(layero, index){
			$(document).keydown(function (e) {//监听键盘动作
	        	if (e.keyCode === 13) {//回车触发提交
	           		$(".layui-layer-btn0").trigger("click");
	        	}
	       	});
			$('#tableName').val(dbt.split('_')[1]);
			$('#moduleName').val(mdu.split('/')[1]);
		},
		yes: function(index) {
			window.location.href = "/generator/code/create?tableName="+$('#tableName').val()+"&moduleName="+$('#moduleName').val()+"&moduleTable="+dbt;
			top.$('.page-loading').hide();
			layer.closeAll();
		},
		cancel: function(index) {
			return true;
		},
		end: function(){
			$(document).unbind();//移除事件——监听键盘动作
		}
   	});
}
//删除
function remove(guid){
	$.operate.remove("确定要删除么？",prefix + "/delete/",{'dictionaryForModuleItems':JSON.stringify([{'guid':guid}])},function(result){
		if(result.code==0){
	        setTimeout(function(){
	            layer.closeAll();
	            table.reload('dhtable');
	        }, 1000);
	    }
	});
}
//打开新标签-字段属性设置
function newTab(mt,mn,ma,isMobile){
	var url = (isMobile?'/system/dictionaryformobilefield?moduleTable=':'/system/dictionaryforfield?moduleTable=') + mt;
    if(top.layui.index)top.layui.index.openTabsPage(url,(ma=='null'||ma==''?mn:ma)+(isMobile?' - 手机':' - PC'));
    else window.open(url);
}
//打开新标签-关联设置
function newTab2(mt,mn,ma){
	var url='/system/dictionaryrelationformodule?moduleTable=' + mt;
    if(top.layui.index){
    	if(ma=='null'||ma==''){
            top.layui.index.openTabsPage(url,mn+'-关联')
    	}else{
    		top.layui.index.openTabsPage(url,ma+'-关联')
    	}
    }else{
        window.open(url)
    }
}

</script>
</body>
</html>